using MicroMsg.Common.Utils;
using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.ImageFilter;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class GoChangeAlbumCover : BasePage
	{
		private const string TAG = "GoChangeAlbumCover";
		internal Grid LayoutRoot;
		internal Grid LayoutContent;
		internal TextBlock titleTxt;
		internal StackPanel ContentPanel;
		internal Button ChoosePicBtn;
		internal Button TakePicBtn;
		internal Button RecommendBtn;
		private bool _contentLoaded;
		public GoChangeAlbumCover()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.GoChangeAlbumCover_Loaded));
		}
		private void GoChangeAlbumCover_Loaded(object sender, RoutedEventArgs e)
		{
			this.ContentPanel.set_Background(R.theme.SNS_MSGPAGE_LISTBK_BRUSH);
		}
		private void ChoosePicBtn_Click(object sender, RoutedEventArgs e)
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/ImageFilter/ImageFilterPage.xaml", new object[]
			{
				new ImageFilterConfig(new ImageFilterCallBack(this.PhotoChooserTaskCompleted), ImageFilterGetPicMode.GetPicMode_Choose_With_Take, 0, 0, null)
				{
					GetPicMode = ImageFilterGetPicMode.GetPicMode_Choose_Exist
				}
			}, false);
		}
		private void TakePicBtn_Click(object sender, RoutedEventArgs e)
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/ImageFilter/ImageFilterPage.xaml", new object[]
			{
				new ImageFilterConfig(new ImageFilterCallBack(this.photoCameraCapture_Completed), ImageFilterGetPicMode.GetPicMode_Choose_With_Take, 0, 0, null)
				{
					GetPicMode = ImageFilterGetPicMode.GetPicMode_Take_Photo,
					isSaveToAlbum = ImageFilterMgr.IsSettingAutoSavePhotos()
				}
			}, false);
		}
		private void RecommendBtn_Click(object sender, RoutedEventArgs e)
		{
			ToolFunction.GotoPageForUserControl("/Source/Plugin/Sns/Common/UI/AlbumCover/BackgroundMasterPage.xaml", null, false);
		}
		private void photoCameraCapture_Completed(Stream resultData)
		{
			if (resultData != null)
			{
				this.ImgOK(resultData);
				base.get_Dispatcher().BeginInvoke(delegate
				{
					base.GoBack();
				});
			}
		}
		private void PhotoChooserTaskCompleted(Stream resultData)
		{
			if (resultData != null)
			{
				Log.smethod_5("GoChangeAlbumCover", "PhotoChooserTaskCompleted");
				resultData.set_Position(0L);
				byte[] array = new byte[100];
				resultData.Read(array, 0, 100);
				ImageFromat imageFormat = ImageUtil.getImageFormat(array);
				resultData.set_Position(0L);
				Log.smethod_5("GoChangeAlbumCover", "image format = " + imageFormat.ToString());
				if (imageFormat != ImageFromat.jpeg)
				{
					if (imageFormat != ImageFromat.const_2)
					{
						Log.smethod_1("GoChangeAlbumCover", "send gif image is not supported");
						MMMessageBox.Show(strings.ChatImgSendFormatError, true, "确定");
						return;
					}
				}
				this.ImgOK(resultData);
				base.get_Dispatcher().BeginInvoke(delegate
				{
					base.GoBack();
				});
				return;
			}
		}
		private void ImgOK(Stream resultData)
		{
			this.LayoutRoot.set_Visibility(1);
			List<TloMedia> list = new List<TloMedia>();
			TloMedia tloMedia = SnsPostService.snsSavePhoto(resultData, true, true);
			list.Add(tloMedia);
			SnsPostService.UploadAndPost(list, null, null, null, 0u, 0, SnsObjectType.MMSNS_OBJECT_BACKGROUND, BgImgType.MMSNS_SETBGIMG_SELFPIC, null);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/AlbumCover/GoChangeAlbumCover.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.LayoutContent = (Grid)base.FindName("LayoutContent");
			this.titleTxt = (TextBlock)base.FindName("titleTxt");
			this.ContentPanel = (StackPanel)base.FindName("ContentPanel");
			this.ChoosePicBtn = (Button)base.FindName("ChoosePicBtn");
			this.TakePicBtn = (Button)base.FindName("TakePicBtn");
			this.RecommendBtn = (Button)base.FindName("RecommendBtn");
		}
	}
}
